//
//  MercDetailItemVM.swift
//  kxf
//
//  Created by Elavatine on 2024/10/16.
//


class MercDetailItemVM: UIView {
    
    let selfHeight = kFitWidth(56)
    
    var copyBlock:(()->())?
    
    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: 0, y: frame.origin.y, width: SCREEN_WIDHT, height: selfHeight))
        self.backgroundColor = .white
        self.isUserInteractionEnabled = true
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var leftTitleLabel: UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 14, weight: .medium)
        
        return lab
    }()
    lazy var detailLabel: UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 14, weight: .medium)
        
        return lab
    }()
    
    lazy var copyButton: UIButton = {
        let btn = UIButton()
        btn.setTitle("复制", for: .normal)
        btn.backgroundColor = WHColor_16(colorStr: "FFB2B2")
        btn.setTitleColor(.black, for: .normal)
        btn.titleLabel?.font = .systemFont(ofSize: 12, weight: .regular)
        btn.layer.cornerRadius = kFitWidth(11)
        btn.clipsToBounds = true
        
        btn.addTarget(self, action: #selector(copyAction), for: .touchUpInside)
        
        return btn
    }()
    lazy var lineView: UIView = {
        let vi = UIView()
        vi.backgroundColor = .COLOR_LIGHT_GREY
        return vi
    }()
}

extension MercDetailItemVM{
    @objc func copyAction() {
        if self.copyBlock != nil{
            self.copyBlock!()
        }
    }
}

extension MercDetailItemVM{
    func initUI() {
        addSubview(leftTitleLabel)
        addSubview(detailLabel)
        addSubview(copyButton)
        addSubview(lineView)
        
        setConstrait()
    }
    func setConstrait() {
        leftTitleLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(24))
            make.centerY.lessThanOrEqualToSuperview()
        }
        detailLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(120))
            make.right.equalTo(kFitWidth(-80))
            make.centerY.lessThanOrEqualToSuperview()
        }
        copyButton.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-20))
            make.width.equalTo(kFitWidth(54))
            make.height.equalTo(kFitWidth(22))
            make.centerY.lessThanOrEqualToSuperview()
        }
        lineView.snp.makeConstraints { make in
            make.left.bottom.width.equalToSuperview()
            make.height.equalTo(kFitWidth(1))
        }
    }
}
